
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>

#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <fstream>
#include <iostream>


using namespace std;


int main (int argc, char* argv[])
{

    // Informiert Test-Listener ueber Testresultate
    CPPUNIT_NS::TestResult testResult;

    // Listener zum Sammeln der Testergebnisse registrieren
    CPPUNIT_NS::TestResultCollector collectedResults;
    testResult.addListener(&collectedResults);

    // Listener zur Ausgabe der Ergebnisse einzelner Tests
    CPPUNIT_NS::BriefTestProgressListener progress;
    testResult.addListener(&progress);
	
	cout << endl;
    cout << "------------------------------------------------------------- EXECUTED TESTS ---" << endl;
    
    // Test-Suite ueber die Registry im Test-Runner einfuegen
    CPPUNIT_NS::TestRunner testRunner;
    testRunner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
    testRunner.run (testResult);

        
    // Resultate im Compiler-Format ausgeben
    CPPUNIT_NS::CompilerOutputter compilerOutputter (&collectedResults, cerr);
    
    cout << "--------------------------------------------------------------- FAILURE LIST ---" << endl; 
    compilerOutputter.printFailuresList();
    
    cout << "----------------------------------------------------------------- STATISTICS ---" << endl;
    compilerOutputter.printStatistics();
    cout << "--------------------------------------------------------------------------------" << endl;


    // Resultate im Compiler-Format ausgeben
    ofstream xmlFileOut("./report/testOutput.xml");
    CPPUNIT_NS::XmlOutputter xmlOut(&collectedResults, xmlFileOut);
    xmlOut.write();

    
    // Rueckmeldung, ob Tests erfolgreich waren
    return collectedResults.wasSuccessful () ? 0 : 1;
	
}
